$(function () {
    //全局定义页数与总条数
    var markid = getUrlString('markid');
    var toysid = getUrlString('toysid');
    // var markid = '3b70887e5d841ff8ab7388ea5f41a5af';
    var page = -1,totalSize = 0,sort= '0';

    var mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#usedList').empty();
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                loadpagedata(page,sort,toysid)
            }
        }
    });

    function loadpagedata (page,sort,toysid) {
        var data = {
            'markid':markid,
            'page':page,
            'sort':sort,
            'toysid':toysid
        };
        getData('post','/niu/apiv3/xiandanv3_gettoylist.php',data,function (data) {
            console.log(data);

            if(data.resultcode === '0' ){
                var append = '';
                if (data.datatoys !== '' && data.datatoys !== null){
                    append += '<li>' +
                        '                   <input type="hidden" class="id" value="'+data.datatoys[0].id+'"> ';
                    // if (data.datatoys[0].ispw === '1'){
                    //     append +='<div class="leftTop">密码</div>'
                    // }
                    append += '                    <div class="saltedPic">' +
                        '                        <img src="'+data.datatoys[0].toyspic+'" alt="">' +
                        '                    </div>' +
                        '                    <div class="right">' +
                        '                    <div class="name">'+data.datatoys[0].toysname+'</div>'+
                        '                    <div class="info">'+data.datatoys[0].intro+'</div>' +
                        // '                        <p class="saltedEggCode">' +
                        // '                        <img class="userface" src="'+data.datatoys[0].userface+'" alt="">' +
                        // '                        <span class="nickName">'+data.datatoys[0].usernick+'</span>' +
                        // '                            <span class="num">'+data.datatoys[0].money2+'</span>' +
                        // '                           <img class="goldCoin" src="../../res/img/common/goldCoin.png" alt="">' +
                        // '                        </p>' +
                        '                    </div>' +
                        '                </li>';
                }

                for (var i = 0;i<data.data.length;i++){
                    append += '<li class="liList">' +
                        '                   <input type="hidden" class="id" value="'+data.data[i].id+'"> ';
                    if (data.data[i].ispw === '1'){
                        append +='<div class="leftTop">密码</div>'
                    }
                    append +=  '                    <img class="userface" src="'+data.data[i].userface+'" alt="">' +
                        '                    <span class="userNick">'+data.data[i].usernick+'</span>' ;
                    if (data.data[i].bukuan_status === '0'){
                        append += '  <img style="width: 1.1rem;vertical-align: middle" src="../../res/img/dj2.png" alt="">' ;
                    }
                    if (data.data[i].isshow === '1'){
                        append +=  '                    <span style="color: #ff0000;font-weight: 600" class="money">￥'+data.data[i].moneyrmb / 100+'</span>' +
                            '                </li>'
                    } else {
                        append +=  '                    <span class="money">'+data.data[i].money2+'</span>' +
                            '                    <img class="goldIcon" src="../../res/img/common/goldCoin.png" alt="">' +
                            '                </li>'
                    }
                }
                $('#usedList').append(append);


                totalSize = totalSize + 10;
                if (totalSize > data.datacount)
                    mRefresh.endUpLoading(true);
                else{
                    mRefresh.endUpLoading(false);
                }
            }else {
                $.toast(data.msg)
            }
        })
    }
    $("#usedList li").live("click", function(){
        var id = $(this).find('.id').val();
        window.location.href = 'dancool://fullweb='+urlView+'saltedEggV2/saltedDetail.html?id='+id;
    });
});
